home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / gnome-games / aisleriot / games / sir_tommy.scm < prev    next >
Encoding:
Text File  |  2009-04-14  |  4.2 KB  |  159 lines

  1. ; AisleRiot - sir_tommy.scm
  2. ; Copyright (C) 2001 Rosanna Yuen <zana@webwynk.net>
  3. ;
  4. ; This game is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2, or (at your option)
  7. ; any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  17. ; USA
  18.  
  19. (define (new-game)
  20.   (initialize-playing-area)
  21.   (set-ace-low)
  22.   (make-standard-deck)
  23.   (shuffle-deck)
  24.  
  25.   (add-normal-slot DECK)
  26.   (add-normal-slot '())
  27.  
  28.   (add-blank-slot)
  29.   (add-normal-slot '())
  30.   (add-normal-slot '())
  31.   (add-normal-slot '())
  32.   (add-normal-slot '())
  33.   (add-carriage-return-slot)
  34.   (add-blank-slot)
  35.   (add-blank-slot)
  36.   (add-blank-slot)
  37.   (add-extended-slot '() down)
  38.   (add-extended-slot '() down)
  39.   (add-extended-slot '() down)
  40.   (add-extended-slot '() down)
  41.  
  42.   (give-status-message)
  43.   (list 7 4))
  44.  
  45. (define (give-status-message)
  46.   (set-statusbar-message (get-stock-no-string)))
  47.  
  48. (define (get-stock-no-string)
  49.   (string-append (_"Stock left:") " " 
  50.          (number->string (length (get-cards 0)))))
  51.  
  52. (define (button-pressed slot-id card-list)
  53.   (and (not (empty-slot? slot-id))
  54.        (= (length card-list) 1)
  55.        (or (= slot-id 1)
  56.        (> slot-id 5))))
  57.  
  58. (define (droppable? start-slot card-list end-slot)
  59.   (cond ((> end-slot 5)
  60.      (= start-slot 1))
  61.     ((> end-slot 1)
  62.      (or (and (= (get-value (car card-list)) ace)
  63.           (empty-slot? end-slot))
  64.          (and (not (empty-slot? end-slot))
  65.           (= (get-value (car card-list))
  66.              (+ 1 (get-value (get-top-card end-slot)))))))
  67.     (#t #f)))
  68.  
  69. (define (button-released start-slot card-list end-slot)
  70.   (and (droppable? start-slot card-list end-slot)
  71.        (cond ((> end-slot 5)
  72.           (move-n-cards! start-slot end-slot card-list))
  73.          ((> end-slot 1)
  74.           (begin
  75.         (move-n-cards! start-slot end-slot card-list)
  76.         (add-to-score! 1)))
  77.          (#t #f))))
  78.  
  79. (define (button-clicked slot-id)
  80.   (and (= slot-id 0)
  81.        (not (empty-slot? 0))
  82.        (empty-slot? 1)
  83.        (deal-cards-face-up 0 '(1))))
  84.  
  85. (define (check-top-card slot f-slot)
  86.   (cond ((= f-slot 6)
  87.      #f)
  88.     ((and (not (empty-slot? f-slot))
  89.           (= (get-value (get-top-card slot))
  90.          (+ 1 (get-value (get-top-card f-slot)))))
  91.      (list f-slot))
  92.     ((and (= (get-value (get-top-card slot)) 
  93.          ace)
  94.           (empty-slot? f-slot))
  95.      (list f-slot))
  96.     (#t (check-top-card slot (+ 1 f-slot)))))
  97.  
  98. (define (button-double-clicked slot-id)
  99.   (and (not (empty-slot? slot-id))
  100.        (or (= slot-id 1)
  101.        (> slot-id 5))
  102.        (check-top-card slot-id 2)
  103.        (deal-cards slot-id (check-top-card slot-id 2))
  104.        (add-to-score! 1)))
  105.  
  106. (define (game-continuable)
  107.   (give-status-message)
  108.   (and (not (game-won))
  109.        (get-hint)))
  110.  
  111. (define (game-won)
  112.   (and (= (length (get-cards 2)) 13)
  113.        (= (length (get-cards 3)) 13)
  114.        (= (length (get-cards 4)) 13)
  115.        (= (length (get-cards 5)) 13)))
  116.  
  117. (define (check-to-foundation slot)
  118.   (cond ((= slot 10)
  119.      #f)
  120.     ((= slot 2)
  121.      (check-to-foundation 6))
  122.     ((and (not (empty-slot? slot))
  123.           (check-top-card slot 2))
  124.      (or (and (= (get-value (get-top-card slot)) ace)
  125.           (list 2 (get-name (get-top-card slot)) (_"empty foundation")))
  126.          (list 1 
  127.            (get-name (get-top-card slot))
  128.            (get-name (get-top-card (car (check-top-card slot 2)))))))
  129.     (#t (check-to-foundation (+ 1 slot)))))
  130.  
  131. (define (move-waste)
  132.   (and (not (empty-slot? 1))
  133.        (not (empty-slot? 0))
  134.        (list 0 (_"Move waste on to a reserve slot"))))
  135.  
  136. (define (dealable?)
  137.   (and (not (empty-slot? 0))
  138.        (list 0 (_"Deal another card"))))
  139.  
  140. (define (get-hint)
  141.   (or (check-to-foundation 1)
  142.       (move-waste)
  143.       (dealable?)))
  144.  
  145. (define (get-options) 
  146.   #f)
  147.  
  148. (define (apply-options options) 
  149.   #f)
  150.  
  151. (define (timeout) 
  152.   #f)
  153.  
  154. (set-features droppable-feature)
  155.  
  156. (set-lambda new-game button-pressed button-released button-clicked
  157. button-double-clicked game-continuable game-won get-hint get-options
  158. apply-options timeout droppable?)
  159.